/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.apt.Action;

import java.io.File;
import java.io.FileOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
import org.apt.Bean.create_lecture_event_bean;

/**
 *
 * @author MinhThang
 */
public class create_lecture_event_action extends org.apache.struts.action.Action {
    
    /* forward name="success" path="" */
    private static final String SUCCESS = "success";
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
         try {
                create_lecture_event_bean f=(create_lecture_event_bean)form;
                FileOutputStream outputStream = null;
                FormFile formFile = null;
                try {
                    formFile = f.getFileImage();
                    String path = getServlet().getServletContext().getRealPath("/images")+"/"+ formFile.getFileName();
                    outputStream = new FileOutputStream(new File(path));
                    outputStream.write(formFile.getFileData());
                } finally {
                    if (outputStream != null) {
                        outputStream.close();
                    }
                }
                 if(f.CreateLectureEvent()){
                       return mapping.findForward(SUCCESS);
                 }
            } catch (Exception e) {
                e.printStackTrace();
            }
        return mapping.findForward("false");
    }
}
